package DataStructureAndAlgorithm.AcWing_每日一题.贪心题;
//链接：https://www.acwing.com/problem/content/description/3821/
import java.util.*;
//贪心：将所有的区间，按照右端点从小到大排序，每次选左端点比上一个选取区间的右端点大的区间即可
class AcWing_3818{
    static class order implements Comparable<order>{
        int left,right;
        order(int l,int r){
            this.left = l;
            this.right = r;
        }

        @Override
        public int compareTo(order temp){
            return this.right - temp.right;
        }

    }

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        order[] orders = new order[n];
        for (int i = 0; i < n; i++){
            int l = in.nextInt();
            int r = in.nextInt();
            orders[i] = new order(l,r);
        }

        Arrays.sort(orders,0,n);

        int res = 0;
        int last = 0;
        for (int i = 0; i < n; i++){
            if (last < orders[i].left){
                res ++;
                last = orders[i].right;
            }
        }
        System.out.println(res);

        in.close();
    }
}